{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import math\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.9402859586706311"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "HD=-(9/14)*np.log2(9/14)-(5/14)*np.log2(5/14)\n",
    "HD"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.6935361388961918 0.8921589282623617 0.9253298887416583 0.8921589282623617\n"
     ]
    }
   ],
   "source": [
    "H1=-(5/14)*(0.4*np.log2(0.4)+0.6*np.log2(0.6))-(4/14)*np.log2(1)-(5/14)*(0.6*np.log2(0.6)+0.4*np.log2(0.4))\n",
    "H2=-(4/14)*(0.5*np.log2(0.5)+0.5*np.log2(0.5))-(8/14)*((6/8)*np.log2(6/8)+(2/8)*np.log2(2/8))-(2/14)*(0.5*np.log2(0.5)+0.5*np.log2(0.5))\n",
    "H3=-(10/14)*(0.6*np.log2(0.6)+0.4*np.log2(0.4))-(4/14)*(0.75*np.log2(0.75)+0.25*np.log2(0.25))\n",
    "H4=-(6/14)*(0.5*np.log2(0.5)+0.5*np.log2(0.5))-(8/14)*((6/8)*np.log2(6/8)+(2/8)*np.log2(2/8))\n",
    "print(H1,H2,H3,H4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.24674981977443933 0.04812703040826949 0.014956069928972804 0.04812703040826949\n"
     ]
    }
   ],
   "source": [
    "print(HD-H1,HD-H2,HD-H3,HD-H4)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.5509775004326937 0.9509775004326937\n"
     ]
    }
   ],
   "source": [
    "H5=-(3/5)*((1/3)*np.log2(1/3)+(2/3)*np.log2(2/3))\n",
    "H6=-(3/5)*((1/3)*np.log2(1/3)+(2/3)*np.log2(2/3))-(2/5)*(0.5*np.log2(0.5)+0.5*np.log2(0.5))\n",
    "print(H5,H6)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.6490224995673063"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "H7=-0.8*(0.75*np.log2(0.75)+0.25*np.log2(0.25))\n",
    "H7"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1.5774062828523454 1.3787834934861753 0.863120568566631 0.9852281360342515\n"
     ]
    }
   ],
   "source": [
    "H10=-(5/14)*np.log2(5/14)-(4/14)*np.log2(4/14)-(5/14)*np.log2(5/14)\n",
    "H11=-(8/14)*np.log2(8/14)-(4/14)*np.log2(4/14)-(2/14)*np.log2(2/14)\n",
    "H12=-(10/14)*np.log2(10/14)-(4/14)*np.log2(4/14)\n",
    "H13=-(6/14)*np.log2(6/14)-(8/14)*np.log2(8/14)\n",
    "print(H10,H11,H12,H13)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.15642756242117528 0.03490542977605791 0.017327903509251417 0.048848615511520824\n"
     ]
    }
   ],
   "source": [
    "print((HD-H1)/H10,(HD-H2)/H11,(HD-H3)/H12,(HD-H4)/H13)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.4325657787314005 1.0000508836861666 0.02059837041578098\n",
      "0.9709505944546686\n"
     ]
    }
   ],
   "source": [
    "H14=-0.4*np.log2(0.4)-0.6*np.log2(0.6)\n",
    "print(0.42/H14,0.971/H14,0.02/H14)\n",
    "print(H14)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0.44598337950138506\n"
     ]
    }
   ],
   "source": [
    "H15=-0.8*np.log2(0.8)-0.2*np.log2(0.2)\n",
    "H15\n",
    "print(0.322/0.722)  "
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "myenv2",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.18"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
